//
//  MovieTableViewCell.m
//  美食百科
//
//  Created by dllo on 16/2/2.
//  Copyright © 2016年 doll. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "Food.h"
#import "UIImageView+WebCache.h"
#define kWidth self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

@interface MovieTableViewCell()
@property(nonatomic, retain) UIImageView *foodImage;

@property(nonatomic, retain) UILabel *nameLabel;

@property(nonatomic, retain) UILabel *contentLabel;

@end
@implementation MovieTableViewCell
-(void)dealloc
{
    [_foodImage release];
    [_nameLabel release];
    [_contentLabel release];
    [_food release];
    [super dealloc];
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.foodImage = [[UIImageView alloc] init];
        [self.contentView addSubview:self.foodImage];
        [_foodImage release];
        
        self.nameLabel = [[UILabel alloc] init];
      //  self.nameLabel.font = [UIFont systemFontOfSize:19];
        self.nameLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.font = [UIFont systemFontOfSize:15];
        self.contentLabel.textColor = self.color;

        self.contentLabel.numberOfLines = 2;
        [self.contentView addSubview:self.contentLabel];
        [_contentLabel release];
    }
    return self;
}

-(void)layoutSubviews
{
    [self subviews];
    
    self.foodImage.frame = CGRectMake(10, 10, kWidth / 3, kHeight - 20);
    
    self.nameLabel.frame = CGRectMake(self.foodImage.frame.origin.x+self.foodImage.frame.size.width + 20, self.foodImage.frame.origin.y, kWidth-(self.foodImage.frame.origin.x+self.foodImage.frame.size.width + 20)-10, self.foodImage.frame.size.height/2);
    
    self.contentLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height, self.nameLabel.frame.size.width, self.nameLabel.frame.size.height);
}

-(void)setFood:(Food *)food
{
    if (_food != food) {
        [_food release];
        _food = [food retain];
    }
    
    [self.foodImage sd_setImageWithURL:[NSURL URLWithString:food.image] placeholderImage:[UIImage imageNamed:@"u=1023456699,842778947&fm=21&gp=0"]];
    
    self.nameLabel.text = food.dishes_name;
    
    self.contentLabel.text = food.dishes_desc;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
